<template>
  <view class="store-list">
    <view class="store-item" v-for="store in stores" :key="store.id" @tap="handleStoreClick(store)">
      <image class="store-logo" :src="store.branch.photo" mode="aspectFit" />
      <view class="store-info">
        <view class="store-name">{{ store.branch.name }}</view>
        <view class="rating">
          <view class="rate-icon"  v-if="store.branch.rating" v-for="n in 5" :key="n">
            <image :src="n <= store.rating
                ? commonStore.baseImageUrl +
                'test-yujia/reservation/pingfen.png'
                : commonStore.baseImageUrl +
                'test-yujia/reservation/pingfenban.png'
              " />
          </view>
          <view class="rate-number"  v-if="store.branch.rating"> 5.0 </view>
          <text class="comment-count">{{ store.commentCount }}条评价</text>
        </view>
        <view class="address">
          <text>{{ store.branch.address }}</text>
        </view>
        <view style="display: flex; gap: 10rpx">
          <view class="store-parking" v-for="tag in store.tags" :key="tag">
            {{ tag }}
          </view>
        </view>
      </view>
      <text class="distance">{{ store.branch.distance.toFixed(2) }}km</text>
    </view>
  </view>
</template>

<script setup>
import { useCommonStore } from "@/store";

const commonStore = useCommonStore();
defineProps({
  stores: {
    type: Array,
    default: () => [],
  },
});

const handleStoreClick = (store) => {
  console.log("store::::", store);
  uni.navigateTo({
    url: `/pages/subpackages/shopCenter/store-detail?branchCode=${store.branch.branchCode}`,
  });
};
</script>

<style lang="scss">
.store-list {
  .store-item {
    background: #fff;
    border-radius: 12rpx;
    padding: 30rpx 26rpx;
    display: flex;
    gap: 20rpx;
    margin-bottom: 36rpx;

    .store-logo {
      width: 140rpx;
      height: 140rpx;
      border-radius: 8rpx;
      background-color: #eee;
      flex-shrink: 0;
    }

    .store-info {
      flex: 1;

      .store-name {
        font-size: 24rpx;
        color: #343434;
        font-weight: bold;
        margin-bottom: 12rpx;
        display: flex;
        align-items: center;

        &::before {
          display: inline-block;
          content: " ";
          width: 24rpx;
          height: 24rpx;
          background-color: #eee;
          margin-right: 6rpx;
        }
      }

      .rating {
        display: flex;
        align-items: center;
        gap: 6rpx;
        margin-bottom: 12rpx;

        .rate-icon {
          display: flex;
          align-items: center;

          image {
            width: 18rpx;
            height: 18rpx;
          }
        }

        .rate-number {
          color: #d0be00;
          font-size: 16rpx;
          font-weight: bold;
        }

        .comment-count {
          font-size: 17rpx;
          color: #000;
          margin-left: 10rpx;
        }
      }

      .address {
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 20rpx;
        color: #4d4d4d;
      }

      .store-parking {
        font-size: 16rpx;
        color: #808f46;
        margin-top: 10rpx;
      }
    }

    .distance {
      color: #808f46;
      font-size: 20rpx;
    }
  }
}
</style>